<template>
  <div id="app">
    <service></service>

    <van-swipe-cell v-for="item in cartList" :key="item.id">
      <van-card
        :num="item.number"
        :price="item.retail_price"
        :title="item.goods_name"
        class="goods-card"
        :thumb="item.list_pic_url"
      />
      <template #right>
        <van-button
          square
          text="删除"
          type="danger"
          class="delete-button"
          @click="remove(item.id)"
        />
      </template>
    </van-swipe-cell>
  </div>
</template>

<script type="text/javascript">
import service from "../../components/homecomp/service.vue";

import { Cart } from "@/api/cart/index";
import { deleteAction } from "@/api/cart/index";
export default {
  data() {
    return {
      openId: localStorage.getItem("openId"),
      cartList: [],
    };
  },
  methods: {
    async remove(id) {
      var res = await deleteAction({
        id: id,
      });

      var res1 = await Cart({
        openId: this.openId,
      });
      this.cartList = res.data;
    },
  },
  computed: {},
  components: {
    service,
  },
  async created() {
    var res = await Cart({
      openId: this.openId,
    });
    this.cartList = res.data;
    console.log(this.cartList);

    // var result = await deleteAction({
    //   id:
    // })
  },
  mounted() {},
};
</script>

<style scoped lang="scss">
.goods-card {
  margin: 0;
}
.delete-button {
  height: 100%;
}
</style>
